NCHAR (Transact |
您所在的位置:网站首页 › sql char nchar › NCHAR (Transact |
NCHAR (Transact-SQL)
项目
02/01/2023
适用于:SQL ServerAzure SQL 数据库Azure SQL 托管实例Azure Synapse AnalyticsAnalytics Platform System (PDW) 根据 Unicode 标准的定义,返回具有指定整数代码的 Unicode 字符。 Transact-SQL 语法约定 语法 NCHAR ( integer_expression )注意 若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档。 参数integer_expression 在数据库的排序规则不包含增补字符 (SC) 标志时,这是从 0 到 65535(0 到 0xFFFF)的正整数。 如果指定的值超出此范围,则返回 NULL。 有关增补字符的详细信息,请参阅 Collation and Unicode Support。 在数据库的排序规则支持 SC 标志时,这是从 0 到 1114111(0 到 0x10FFFF)的正整数。 如果指定的值超出此范围,则返回 NULL。 返回类型当默认数据库排序规则不支持增补字符时,为 nchar(1)。 当默认数据库排序规则支持增补字符时,为 nvarchar(2)。 如果 integer_expression 参数在范围 0 - 0xFFFF 内,则仅返回一个字符。 对于较高的值,NCHAR 返回相应的代理项对。 请勿使用 NCHAR() + NCHAR(\) 构造代理项对。 而应使用支持增补字符的数据库排序规则,然后为代理项对指定 Unicode 码位。 下面的示例演示构建代理项对的旧式方法以及指定 Unicode 码位的首选方法。 CREATE DATABASE test COLLATE Finnish_Swedish_100_CS_AS_SC; DECLARE @d NVARCHAR(10) = N'𣅿'; -- Old style method. SELECT NCHAR(0xD84C) + NCHAR(0xDD7F); -- Preferred method. SELECT NCHAR(143743); -- Alternative preferred method. SELECT NCHAR(UNICODE(@d)); 示例 A. 使用 NCHAR 和 UNICODE以下示例使用 UNICODE 和 NCHAR 函数输出 UNICODE 字符串中的第二个字符的 NCHAR 值和 København(Unicode 字符),并输出实际的第二个字符 ø。 DECLARE @nstring NCHAR(8); SET @nstring = N'København'; SELECT UNICODE(SUBSTRING(@nstring, 2, 1)), NCHAR(UNICODE(SUBSTRING(@nstring, 2, 1))); GO下面是结果集: ----------- - 248 ø (1 row(s) affected) B. 使用 SUBSTRING、UNICODE、CONVERT 和 NCHAR以下示例使用 SUBSTRING、UNICODE、CONVERT 和 NCHAR 函数打印字符串 København 中的字符数、Unicode 字符和每个字符的 UNICODE 值。 -- The @position variable holds the position of the character currently -- being processed. The @nstring variable is the Unicode character -- string to process. DECLARE @position INT, @nstring NCHAR(9); -- Initialize the current position variable to the first character in -- the string. SET @position = 1; -- Initialize the character string variable to the string to process. -- Notice that there is an N before the start of the string. This -- indicates that the data following the N is Unicode data. SET @nstring = N'København'; -- Print the character number of the position of the string you are at, -- the actual Unicode character you are processing, and the UNICODE -- value for this particular character. PRINT 'Character #' + ' ' + 'Unicode Character' + ' ' + 'UNICODE Value'; WHILE @position |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |